#include <bits/stdc++.h>
#define ll long long
using namespace std;

template<typename ...Args>
signed debug(const char*str,Args&&...args){return fprintf(stderr,str,args...);}

inline static int read(){
    int sum=0,neg=false,ch=getchar();
    while(!isdigit(ch)) neg|=(ch=='-'),ch=getchar();
    while(isdigit(ch)) sum=sum*10+(ch^48),ch=getchar();
    return neg?-sum:sum;
}

int n,a[1000005],b[2000005],rk[1000005],fa[1000005];
int find(int x){return fa[x]?fa[x]=find(fa[x]):x;}
void merge(int a,int b){fa[find(a/2)]=find(b/2);}
bool check(int a,int b){return find(a)==find(b);}
char str[1000005]; int*vec[1000005],siz[1000005]; bool bit[1000005];
void clear(int p){free(vec[p]),vec[p]=nullptr,siz[p]=0;}
void add(int p){for(int i=0;i<siz[p];i++) bit[vec[p][i]]=1; clear(p);}
signed main(){
    freopen("string.in","r",stdin);
    freopen("string.out","w",stdout);
    int T=read();
    while(T--){
        for(int i=1;i<=n;i++) clear(i);
        n=read(),rk[n+1]=0,memset(fa+1,0,4*n),memset(bit+1,0,n);
        for(int i=1;i<=n;i++) a[i]=read()+1,rk[a[i]]=i;
        for(int i=1;i<2*n;i++) b[i]=read(); str[a[1]]='a';
        for(int i=1;i<2*n;i++) if(max(i,2*n-i)<b[i]) goto Continue;
        for(int i=1,p,R=0,l;i<2*n;i++){
            l=i>R?0:min(b[2*p-i],R-i); if(b[i]<l) goto Continue;
            while(++l<=b[i]) if((l^i)&1) merge(i-l+1,i+l+1);
            if(i+b[i]>R) R=i+b[i],p=i;
        }
        for(int i=1;i<2*n;i++){
            int u=find((i-b[i])/2),v=find((i+b[i])/2+1);
            if(u && v<=n) siz[u]++,siz[v]++; if(u==v) goto Continue;
        }
        for(int i=1;i<=n;i++) if(siz[i]) vec[i]=(int*)malloc(4*siz[i]),siz[i]=0;
        for(int i=1;i<2*n;i++){
            int u=find((i-b[i])/2),v=find((i+b[i])/2+1);
            if(u && v<=n) vec[u][siz[u]++]=v,vec[v][siz[v]++]=u;
        } add(find(a[1]));
        for(int i=2,w=0;i<=n;i++){
            int p=a[i];
            if(rk[a[i-1]+1]>rk[p+1]) str[p]=++w+'a',memset(bit+1,0,n);
            else if(bit[find(p)]) str[p]=++w+'a',memset(bit+1,0,n);
            else str[p]=w+'a'; add(find(p)); if(w==26) goto Continue;
        }
        for(int i=1;i<=n;i++) if(str[find(i)]!=str[i]) goto Continue;
        puts(str+1); continue; Continue: puts("-1");
    } return 0;
}
